//
//  MTFoucsVC.m
//  met
//
//  Created by 李晓俊 on 2019/5/11.
//  Copyright © 2019 李晓俊. All rights reserved.
//

#import "MTFoucsVC.h"
#import "HJTabViewControllerPlugin_TabViewBar.h"
#import "HJDefaultTabViewBar.h"
//我关注的
#import "MTMyFoucsVC.h"
//关注我的
#import "MTFoucsMineVC.h"
@interface MTFoucsVC ()<HJTabViewControllerDataSource, HJTabViewControllerDelagate, HJDefaultTabViewBarDelegate>

@property (nonatomic,strong) NSString *myfoucsCount;
@property (nonatomic,strong) NSString *foucsmineCount;

@property (nonatomic,strong) HJDefaultTabViewBar *tabViewBar;
@end

@implementation MTFoucsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tabDataSource = self;
    self.tabDelegate = self;
    self.tabViewBar = [[HJDefaultTabViewBar alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 75)];
    self.tabViewBar.delegate = self;
    HJTabViewControllerPlugin_TabViewBar *tabViewBarPlugin = [[HJTabViewControllerPlugin_TabViewBar alloc] initWithTabViewBar:self.tabViewBar delegate:nil];
    [self enablePlugin:tabViewBarPlugin];
    
    self.navigationItem.title = @"关注列表";
    self.view.backgroundColor = KBackColor;
    
    //初始化
    self.myfoucsCount = @"0";
    self.foucsmineCount = @"0";
     
    [self CreateNav];
}
-(void)CreateNav
{
    //默认返回事件
    UIBarButtonItem *leftBtn = [[UIBarButtonItem alloc ]initWithImage:[UIImage imageWithOriginalName:@"返回黑色"] style:UIBarButtonItemStyleDone target:self action:@selector(returnAction)];
    self.navigationItem.leftBarButtonItem = leftBtn;
}
- (void)returnAction {
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - HJDefaultTabViewBarDelegate
- (NSInteger)numberOfTabForTabViewBar:(HJDefaultTabViewBar *)tabViewBar {
    return [self numberOfViewControllerForTabViewController:self];
}
- (id)tabViewBar:(HJDefaultTabViewBar *)tabViewBar titleForIndex:(NSInteger)index {
    if (index == 0) {
        NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n我关注的",self.myfoucsCount]];
        [attrString addAttribute:NSFontAttributeName value:SBFONT(24) range:NSMakeRange(0,self.myfoucsCount.length)];
        return attrString;
    }else if (index == 1) {
        NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n关注我的",self.foucsmineCount]];
        [attrString addAttribute:NSFontAttributeName value:SBFONT(24) range:NSMakeRange(0,self.foucsmineCount.length)];
        return attrString;
    }
    return @"";
}
- (void)tabViewBar:(HJDefaultTabViewBar *)tabViewBar didSelectIndex:(NSInteger)index {
    BOOL anim = labs(index - self.curIndex) > 1 ? NO: YES;
    [self scrollToIndex:index animated:anim];
}
#pragma mark -
- (NSInteger)numberOfViewControllerForTabViewController:(HJTabViewController *)tabViewController {
    return 2;
}
- (UIViewController *)tabViewController:(HJTabViewController *)tabViewController viewControllerForIndex:(NSInteger)index {
    if (index == 0) {
        MTMyFoucsVC *vc =  [[MTMyFoucsVC alloc] init];
        vc.removeFocus = ^(NSString * count) {
            self.myfoucsCount = count;
            [self.tabViewBar reloadTabBar];
        };
        vc.removeFocus2 = ^(NSString * count) {
            self.foucsmineCount = count;
            [self.tabViewBar reloadTabBar];
        };
        return vc;
    }
    MTFoucsMineVC *vc =  [[MTFoucsMineVC alloc] init];
    vc.removeFocus = ^(NSString * count) {
        self.foucsmineCount = count;
        [self.tabViewBar reloadTabBar];
    };
    vc.removeFocus2 = ^(NSString * count) {
        self.myfoucsCount = count;
        [self.tabViewBar reloadTabBar];
    };
    return vc;
}
- (UIEdgeInsets)containerInsetsForTabViewController:(HJTabViewController *)tabViewController {
    return UIEdgeInsetsMake(NavHeight, 0, 0, 0);
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}
@end
